# -*- coding: utf-8 -*-
# @Project: 芒果测试平台
# @Description: 
# @Time   : 2025-02-26 20:08
# @Author : 毛鹏
import asyncio
import json

from mangotools.mangos import Mango

from src import test_process, log
from src.consumer import SocketConsumer
from src.models.socket_model import QueueModel
from src.settings import settings
from src.tools.send_global_msg import global_consumer_news


class LinuxLoop:

    def __init__(self):
        self.loop = Mango.t()

    def handle_notification(self, value):
        print(value.msg)


async def run():
    loop = LinuxLoop()
    await test_process(loop)
    with open('test.json', 'r', encoding='utf-8') as f:
        data = json.load(f)
        await SocketConsumer.add_task(QueueModel(func_name=data.get('func_name'), func_args=data.get('func_args')))


async def run_func():
    from src.models.ui_model import CaseModel
    from src.services.ui.case_flow import CaseFlow
    CaseFlow.parent = LinuxLoop()
    with open('test.json', 'r', encoding='utf-8') as f:
        data = json.load(f)
        await CaseFlow.execute_task(CaseModel(**data.get('func_args')))


async def main():
    settings.IS_DEBUG = True
    log.set_debug(settings.IS_DEBUG)
    asyncio.create_task(global_consumer_news())
    asyncio.create_task(run())
    while True:
        await asyncio.sleep(0.2)


asyncio.run(main())
